package org.openkanban.client.ui.presenter;

import org.openkanban.client.ui.board.ActivityView;
import org.openkanban.client.ui.board.WhiteBoardView;
import org.openkanban.client.util.RootPanel;
import org.openkanban.shared.dto.ActivityDto;

import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.Response;
import com.smartgwt.client.util.SC;

/**
 * Callback that handles new activity request
 */
public class GetNewActivityByIdRequestCallback implements RequestCallback {

    @Override
    public void onResponseReceived(Request request, Response response) {
	ActivityDto activityDto = new ActivityDto(response.getText());
	if (response.getStatusCode() < 300 && activityDto.isCallSuccessfull()) {
	    WhiteBoardView whiteBoardView = RootPanel.main.getBoard().getWhiteBoardView();
	    ActivityView activityView = new ActivityView(activityDto, whiteBoardView.getBoardDto().getBoardId());
	    whiteBoardView.addActivity(activityView);
	} else {
	    SC.say("Fehler: " + response.getStatusText());
	}
    }

    @Override
    public void onError(Request request, Throwable exception) {
    }

}
